package g

import "strings"

type Sample struct {
	Metric    string            `json:"metric"`
	Timestamp int64             `json:"timestamp"`
	Value     interface{}       `json:"value"`
	Tags      map[string]string `json:"tags"`
}

func NewSample(ts int64, ip, metric string, val interface{}, tags ...string) *Sample {
	s := &Sample{
		Metric:    "snmp_" + strings.ReplaceAll(metric, ".", "_"),
		Timestamp: ts,
		Value:     val,
	}

	s.Tags = make(map[string]string)
	s.Tags["ident"] = ip

	for i := 0; i < len(tags); i++ {
		pair := strings.Split(tags[i], "=")
		if len(pair) != 2 {
			continue
		}

		s.Tags[pair[0]] = pair[1]
	}

	return s
}
